import 'package:flutter/material.dart';
import 'package:flutter_app/models/character.dart';
import 'package:flutter_app/widgets/character_widget.dart';

class CharacterListingScreen extends StatefulWidget {
  @override
  _CharacterListingScreenState createState() => _CharacterListingScreenState();
}

class _CharacterListingScreenState extends State<CharacterListingScreen> {
  PageController _pageController;
  int currentPage = 0;

  @override
  void initState() {
    _pageController = PageController(
        viewportFraction: 1.0, initialPage: currentPage, keepPage: true);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: Icon(Icons.arrow_back_ios),
        actions: <Widget>[
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 8.0),
            child: Icon(Icons.search),
          )
        ],
      ),
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.only(bottom: 20.0),
          child: Column(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(left: 32.0, top: 10),
                child: RichText(
                  text: TextSpan(children: [
                    TextSpan(
                        text: "Despicable Me",
                        style: Theme.of(context).textTheme.display2),
                    TextSpan(text: "\n"),
                    TextSpan(
                        text: "Characters",
                        style: Theme.of(context).textTheme.display1)
                  ]),
                ),
              ),
              Expanded(
                  child: PageView(controller: _pageController, children: [
                for (var i = 0; i < characters.length; i++)
                  CharacterWidget(
                    currentCharacter: characters[i],
                    pageController: _pageController,
                    currentPage: i,
                  )
              ]))
            ],
          ),
        ),
      ),
    );
  }
}
